package cn.gdrj.est.service.impl;

import cn.gdrj.est.constants.Constants;
import cn.gdrj.est.dao.MalfunctionOptionsDao;
import cn.gdrj.est.dto.MalfunctionOptionsDTO;
import cn.gdrj.est.entity.MalfunctionOptions;
import cn.gdrj.est.service.MalfunctionOptionsService;
import cn.gdrj.est.util.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 故障选项业务组件
 *
 * @author jun
 * @date 2021/11/9
 */
@Service
public class MalfunctionOptionsServiceImpl implements MalfunctionOptionsService {

    private final MalfunctionOptionsDao malfunctionOptionsDao;

    public MalfunctionOptionsServiceImpl(MalfunctionOptionsDao malfunctionOptionsDao) {
        this.malfunctionOptionsDao = malfunctionOptionsDao;
    }

    @Override
    public List<MalfunctionOptionsDTO> listByMalfId(Long malfId) {
        List<MalfunctionOptions> malfunctionOptions =
                malfunctionOptionsDao.listByMalfId(malfId, Constants.EST_NOT);

        // BeanUtils/MapStruct(完成各种值对象的相互转换)
        return BeanUtils.convertToDTOList(malfunctionOptions,MalfunctionOptionsDTO.class);
    }

    @Override
    public List<MalfunctionOptionsDTO> listByIds(List<Long> ids) {
        List<MalfunctionOptions> malfunctionOptions =malfunctionOptionsDao.listByIds(ids);
        return BeanUtils.convertToDTOList(malfunctionOptions,MalfunctionOptionsDTO.class);
    }

    // private MalfunctionOptionsDTO convertToDTO(MalfunctionOptions options){
    //     MalfunctionOptionsDTO dto = new MalfunctionOptionsDTO();
    //     BeanUtils.copyProperties(options,dto);
    //     return dto;
    // }


    // private List<MalfunctionOptionsDTO> convertToDTO(List<MalfunctionOptions> options){
    //     List<MalfunctionOptionsDTO> dtos = new ArrayList<>();
    //     for (MalfunctionOptions option : options) {
    //         MalfunctionOptionsDTO dto = convertToDTO(option);
    //         dtos.add(dto);
    //     }
    //     return dtos;
    // }
}
